﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Red.Controls.Shell;
using Red.Controls.Utils;

namespace Red.Launcher.Dialogs
{
    public partial class UserSignin : RedDialog
    {
        #region Public Dependency Properties

        public static readonly DependencyProperty UsernameProperty = DependencyProperty.Register( "Username", typeof( string ), typeof( UserSignin ) );

        #endregion Public Dependency Properties

        #region Public Properties

        public bool IsUsernameReadOnly { get; set; }
        public string Username
        {
            get { return (string)GetValue( UsernameProperty ); }
            set { SetValue( UsernameProperty, value ); }
        }
        public string Password => _password.Password;
        public string Domain => _domain.Text;
        public bool ShowDomain { get; set; } = true;

        public bool IsValid => Helpers.ValidateElement( _username );

        #endregion Public Properties

        #region C-Tor

        public UserSignin()
        {
            InitializeComponent();
            Title = "Red Launcher: Sign in";

            Closing += UserSignin_Closing;
        }

        #endregion C-Tor

        #region Event 

        private void UserSignin_Closing( object sender, CancelEventArgs e )
        {
            Helpers.RefreshBindingValues( _username, TextBox.TextProperty );

            if ( DialogResult.Equals( true ) && !IsValid )
            {
                e.Cancel = true;
            }
        }

        #endregion Event Handlers
    }
}
